package vue;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import model.*;

public class VueTextuelle extends Thread{
	
	private static Fourmiliere fourmiliere;
	private static ArrayList<Fourmi> nosFourmis;
	private int nbOeufs = 0;
	private int nbLarves = 0;
	private int nbNymphes = 0;

	public VueTextuelle(Fourmiliere fourm) {
		fourmiliere = fourm;
		nosFourmis = fourm.getNosFourmis();
	}

	public void run() {
		Timer timer = new Timer();

		timer.scheduleAtFixedRate(new TimerTask() {
			public void run() {
				parcourirFourmis();
				construireRapport();
			}
		}, 0, 1000);

	}

	public void parcourirFourmis(){
		Role role;
		EnumStade stade;
		
		nbOeufs = 0;
		nbLarves = 0;
		nbNymphes = 0;
		Ouvriere.resetCpt();
		Soldat.resetCpt();
		Indsexue.resetCpt();
		Reine.resetCpt();
		
		System.out.println("*** FOURMILIERE ***");
		System.out.println(nosFourmis.size());
		
		for(int i = 0; i < nosFourmis.size(); i++){
			System.out.println("Fourmi [" + i + "] - [" + nosFourmis.get(i).getX() + ", " + nosFourmis.get(i).getY() + "]");
			
			role = nosFourmis.get(i).getRole();
			stade = nosFourmis.get(i).getStade();
			
			role.compter();

			switch(stade){
				case OEUF: nbOeufs++; break;
				case LARVE: nbLarves++; break;
				case NYMPHE: nbNymphes++; break;
			}
			
			System.out.println("\tRole: " + role);
			System.out.println("\tStade: " + stade);
		}
	}
	
	public void construireRapport(){
		System.out.println("\n*** TOTAL ***");
		System.out.println("Oeufs: " + nbOeufs);
		System.out.println("Larves: " + nbLarves);
		System.out.println("Nymhpes: " + nbNymphes);
		System.out.println("Ouvrieres: " + Ouvriere.getCpt());
		System.out.println("Soldats: " + Soldat.getCpt());
		System.out.println("Sexuees: " + Indsexue.getCpt());
		System.out.println("Reine: " + Reine.getCpt());
		System.out.println("\n******************************\n");
	}
}
